package com.qiqu.controller;

import com.qiqu.commen.Const;
import com.qiqu.entity.UsersLikeArticle;
import com.qiqu.service.UsersLikeArticleService;
import com.qiqu.utils.JSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import static com.qiqu.commen.Const.PAGE_SIZE;


/**
 * (UsersLikeArticle)表控制层
 *
 * @author makejava
 * @since 2021-04-12 20:47:36
 */
@RestController
@RequestMapping("usersLikeArticle")
@Api(value = "喜欢相关接口",tags = {"喜欢相关接口controller"})
public class UsersLikeArticleController {
    @Resource
    private UsersLikeArticleService usersLikeArticleService;


    //用户喜欢
    @ApiOperation(value = "用户喜欢文章--sora", notes = "用户喜欢文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "articleId", value = "喜欢的文章id", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "userId", value = "喜欢者的id", required = true, dataType = "string", paramType = "query")
    })
    @GetMapping("/like")
    public JSONResult enCollection(@RequestParam("userId") String userId, @RequestParam("articleId") String articleId){

        return JSONResult.ok(usersLikeArticleService.Like(userId,articleId));
    }

    //用户取消喜欢
    @ApiOperation(value = "用户取消喜欢--sora", notes = "用户取消喜欢")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "取消喜欢的人的id", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "articleId", value = "取消喜欢的文章id", required = true, dataType = "string", paramType = "query")
    })
    @GetMapping("/cancleLike")
    public JSONResult unCollection(String userId,String articleId){
        return JSONResult.ok(usersLikeArticleService.cancleLike(userId,articleId));
    }

    //查询文章与用户关系
    @ApiOperation(value = "查询文章与用户关系--kk", notes = "查询文章与用户关系")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "articleId", value = "文章id", required = true, dataType = "string", paramType = "query")
    })
    @GetMapping("/isLike")
    public JSONResult userLike(HttpServletRequest request,String articleId){
        String userId=request.getHeader("userId");
        return JSONResult.ok(usersLikeArticleService.isLike(userId,articleId));
    }

    //获取用户文章被点赞信息
    @ApiOperation(value = "获取用户文章被点赞信息--fk",notes = "获取用户文章被点赞信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name="page",value = "页码",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name="userId",value = "用户id",required = true,dataType = "string",paramType = "query"),
    })
    @GetMapping("/getLike")
    public JSONResult getLike(Integer page,String userId) {
        if(page == null){
            page=1;
        }
        return JSONResult.ok(usersLikeArticleService.getLikeArticle(page,PAGE_SIZE,userId));
    }

    //获取未读点赞信息数
    @ApiOperation(value = "获取未读点赞信息数--fk",notes = "获取未读点赞信息数")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name="userId",value = "用户id",required = true,dataType = "string",paramType = "query")
    })
    @GetMapping("/getLikeCounts")
    public JSONResult getLikeCounts(String userId) {
        return JSONResult.ok(usersLikeArticleService.queryStatusCount(userId));
    }

    //更新状态信息
    @ApiOperation(value = "更新状态信息--fk",notes = "更新状态信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name="userId",value = "用户id",required = true,dataType = "string",paramType = "query")
    })
    @GetMapping("/updateLike")
    public JSONResult updateLike(String userId) {
        return JSONResult.ok(usersLikeArticleService.updateStatus(userId));
    }


}